import { createSlice } from "@reduxjs/toolkit";

const initialState = {
    value: 0,
    statues: 'idle'
}

export const counterReducer = createSlice({
    name: 'counter',
    initialState,
    reducers: {
        increment: (state) => {
            state.value += 1
        },
        decrement: (state) => {
            state.value -= 1
        },

        incrementByAmount: (state,action) => {
            console.log(action);
            
            state.value += action.payload
        }
    }
})

//定义action
export const { increment, decrement,incrementByAmount } = counterReducer.actions

//取数据
export const selectCount = (state) => {
    // console.log(state);
    
    return state.counter.value
}

export default counterReducer.reducer